<?php

	// TITLE: Demographic_type AUTO MODEL
	// FILE: scaffolding/model/demographic_type.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createDemographicType = function($con, $demographicType) {
		$sql = 'INSERT INTO demographic_type (id, title, code, description) VALUES (';
		$sql .= $demographic_type->getId() . ', ';
		$sql .= $demographic_type->getTitle() . ', ';
		$sql .= $demographic_type->getCode() . ', ';
		$sql .= $demographic_type->getDescription() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readDemographicType = function($con, $id) {
		$sql = 'SELECT * FROM demographic_type WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$demographicType = new DemographicType();
			$demographicType->setId(result[0]);
			$demographicType->setTitle(result[1]);
			$demographicType->setCode(result[2]);
			$demographicType->setDescription(result[3]);
		} else {
			$demographicType = false;
		}
		return $demographicType;
	};

	$updateDemographicType = function($con, $demographicType) {
		$sql = 'UPDATE demographic_type SET ';
		$sql .= 'id = ' . $demographic_type->getId() . ', ';
		$sql .= 'title = ' . $demographic_type->getTitle() . ', ';
		$sql .= 'code = ' . $demographic_type->getCode() . ', ';
		$sql .= 'description = ' . $demographic_type->getDescription() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteDemographicType = function($con, $id) {
		$sql = 'DELETE FROM demographic_type WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listDemographicType = function($con) {
		$sql = 'SELECT * FROM demographic_type';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$demographicTypes = array();
			while ($result = mysqli_fetch_array($results)) {
				$demographicType = new DemographicType();
				$demographicType->setId(result[0]);
				$demographicType->setTitle(result[1]);
				$demographicType->setCode(result[2]);
				$demographicType->setDescription(result[3]);
				$demographicTypes[] = demographicType;
			}// end while
		} else {
			$demographicTypes = false;
		}
		return $demographicTypes;
	};

